package cn.zhp.config;

import cn.zhp.interceptor.ResourcesInterceptor;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
/**
 *
 整合事务控制
 a.开启扫描服务层
 b.声明事务管理器
 c.开启事务注解支持
 d.在需要事务控制的服务层的类上添加事务注解
 */
@ComponentScan(basePackages = {"cn.zhp.service", "cn.zhp.aspect"})
@PropertySource(value = "classpath:sys.properties",encoding = "utf-8")//引入配置文件
@EnableTransactionManagement
@EnableAspectJAutoProxy     //开启aop注解支持
public class SpringService {

    @Bean
    public DataSourceTransactionManager getTransactionManager(DruidDataSource dataSource){
        return new DataSourceTransactionManager(dataSource);
    }

    //创建权限拦截器对象
    @Bean
    public ResourcesInterceptor getResourcesInterceptor(){
        return new ResourcesInterceptor();
    }

}
